// 搜索框点击显示下拉面板
const searchInput = document.getElementById('search-input');
const searchDropdown = document.getElementById('search-dropdown');
const searchContainer = document.querySelector('.search-container');
const resultPage = document.getElementById('result-page');

searchInput.addEventListener('focus', () => {
  searchDropdown.style.display = 'block';
});

// 点击页面其他区域隐藏下拉面板
document.addEventListener('click', (e) => {
  if (!searchContainer.contains(e.target)) {
    searchDropdown.style.display = 'none';
  }
});

// 跳转到搜索结果页面
function goToResult(keyword) {
  const resultTitle = document.getElementById('result-title');
  resultTitle.textContent = `搜索结果：${keyword}`;
  searchContainer.style.display = 'none';
  resultPage.style.display = 'block';
}

// 返回搜索页面
function goBack() {
  resultPage.style.display = 'none';
  searchContainer.style.display = 'block';
}

// 搜索按钮逻辑
const searchBtn = document.getElementById('search-btn');
searchBtn.addEventListener('click', () => {
  const keyword = searchInput.value.trim();
  if (keyword) {
    goToResult(keyword);
    // 实际项目中可在此处添加“添加到历史搜索”逻辑
  }
});
